<?php 
class Import{
	
	function &getInstance(){
		static $singleton;

		if (!$singleton)
		$singleton = new Import();

		return $singleton;
	}
	
	public function &singleton($class,$param=false) {
		static $instances;

		$key = (isset($param['instance']) ? $class.'_'.$param['instance'] : $class);
		$param['fromGetInstance'] = true;
		
		if (!is_array($instances)) {
			$instances = array();
		}

		if (!isset($instances[$key])) {
			$instances[$key] =& new $class($param);
		}
	
		return $instances[$key];
	}
    
	public function loadClass($className, $path_class='', $prefix='',$param=array(), $singleton=-1){
		$className = strtolower($className);
		
//		echo '<li>'.$path_class.$className.'.class.php';
		if (!class_exists($className)){
				if(!empty($path_class)){
//					echo '<li>'.$path_class.$className.'.class.php';
					if(file_exists($path_class.$className.'.class.php'))
						include $path_class.$className.'.class.php';
					elseif(file_exists($path_class.$className.'.php'))
						include $path_class.$className.'.php';
					else
						echo '<li>Impossible de charger la classe '.$className.': '.E_USER_ERROR;
						
				}else
					echo '<li>Impossible de charger la classe '.$className.': '.E_USER_ERROR;
		}
		
		$forceSingleton = false;
		if(is_callable(array($className, 'getSingleton'), false, $callable_name))
			eval('$forceSingleton = '.$callable_name.'();');

			
		if($singleton > 0 || ($forceSingleton && $singleton != false)){			
			return Import::singleton($className,$param);
		}
		else
			return new $className($param);
	}
	
	
	
}
?>